package com.heima.exam.p1;

public class FeedAnimal {
    public static void main(String[] args) {
        Animal a = new Cat();
        Animal a1 = new Dog();
        Animal a2 = new Pig();
        feedAnimal(a);
        feedAnimal(a1);
        feedAnimal(a2);
    }

    static void feedAnimal(Animal a) {
        a.eat();
        a.drink();
        if (a instanceof Cat) {
            ((Cat) a).catchMouse();
        }
    }
}

abstract class Animal {
    abstract void drink();

    void eat() {
        System.out.println("aaaaaa");
    }
}

class Cat extends Animal {
    void catchMouse() {
        System.out.println(" cat 抓老鼠");
    }

    @Override
    void drink() {
        System.out.println(" cat 喝水");
    }
}

class Dog extends Animal {

    @Override
    void drink() {
        System.out.println(" Dog 喝水");
    }
}

class Pig extends Animal {

    @Override
    void drink() {
        System.out.println(" Pig 喝水");
    }
}
